<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="test"></div>
    <script src="../lib//react.development.js"></script>
    <script src="../lib/react-dom.development.js"></script>
    <script src="../lib/babel.min.js"></script>

    <script type="text/babel">
        class Weather extends React.Component {
            constructor(props) {
                super(props)
                this.state = { isHot: true, wind: '大风' }
                this.clickHandler = this.clickHandler.bind(this)
            }
            clickHandler(){
                // 状态不可直接更改
                // this.state.isHot = !this.state.isHot

                // 通过 setState 修改状态
                const {isHot} = this.state
                this.setState({ isHot: !isHot }) // 不会替换 wind 属性
            }
            render() {
                const {isHot,wind} = this.state
                return <h1 onClick={this.clickHandler}>今天天气{isHot ? '炎热' : '凉爽'}，{wind}</h1>
            }
        }
        ReactDOM.render(<Weather />, document.getElementById('test'))
    </script>
</body>

</html>